/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package load.util;

import core.DispatcherPort;
import core.InPort;
import core.StdNode;
import core.TriggerPort;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author Jelle
 */
public class Timer extends StdNode {

    private InPort delay = new InPort(java.lang.Integer.class);
    private DispatcherPort dispatch = new DispatcherPort();
    private static javax.swing.Timer tmr = new javax.swing.Timer(1000, null);

    private TriggerPort start = new TriggerPort() {
        @Override
        protected void callInternal() {
            tmr = new javax.swing.Timer((Integer) delay.getValue(), new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dispatch.callTargets();
                }
            });
            tmr.start();
        }
    };
    
    private TriggerPort stop = new TriggerPort() {
        @Override
        protected void callInternal() {
            tmr.stop();
        }
    };

    public Timer() {
        this.autoPutPorts();
    }
}
